<template>
  <div class="SJZYLB">
    <el-card class="box-card _body">
      <div slot="header" class="clearfix">
        <span style="font-weight: 700; font-size: 20px">数据值域列表</span>
      </div>
      <div class="query">
        值域代码
        <el-input
          v-model="query.filter.code"
          size="small"
          style="width: 200px"
        ></el-input>
        值域名称
        <el-input
          v-model="query.filter.name"
          size="small"
          style="width: 200px"
        ></el-input>
        版本号
        <el-input
          size="small"
          style="width: 200px; margin-top: 10px"
          v-model="query.filter.version"
        ></el-input>
        状态
        <el-select
          size="small"
          v-model="query.filter.status"
          placeholder="请选择"
        >
          <el-option label="正常" :value="0"> </el-option>
          <el-option label="弃用" :value="1"> </el-option>
        </el-select>
        <el-button
          size="small"
          icon="el-icon-search"
          style="margin-left: 10px"
          type="primary"
          @click="getTabList(true)"
        ></el-button>
        <el-button
          size="small"
          icon="el-icon-plus"
          type="success"
          style="margin-left: 10px"
          @click="dialogVisible = true"
        ></el-button>
      </div>
      <div class="main" style="margin-top: 10px">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          stripe
          border
          height="555"
          v-loading="isLoading"
        >
          <el-table-column prop="name" label="值域代码名称"> </el-table-column>
          <el-table-column prop="code" label="值域代码" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="valueName" label="值名称"> </el-table-column>
          <el-table-column prop="value" label="值"> </el-table-column>
          <el-table-column prop="version" label="版本号"> </el-table-column>
          <!-- <el-table-column label="分类编码" prop="category"> </el-table-column>
          <el-table-column prop="categoryName" label="分类名称">
          </el-table-column>
          <el-table-column prop="levelName" label="标准等级"> </el-table-column> -->
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              {{ scope.row.status == 0 ? "正常" : "弃用" }}
            </template>
          </el-table-column>
          <el-table-column prop="descrption" label="说明描述">
          </el-table-column>
          <el-table-column prop="name" label="选项" width="140" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-edit"
                @click="edit(scope.row)"
              ></el-button>
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-delete"
                @click="del(scope.row.id)"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="page" style="text-align: right">
        <span style="float: left">总共 {{ total }} 条记录</span>
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page="query.currentPage"
          :page-size="query.pageSize"
          :total="total"
          @current-change="page_change"
        >
        </el-pagination>
      </div>
    </el-card>
    <!-- 弹层 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form
        label-position="right"
        label-width="120px"
        :model="formLabelAlign"
      >
        <el-form-item
          label="*值域代码名称"
          style="display: inline-block; width: 50%"
        >
          <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item>
        <el-form-item
          label="*值域代码"
          style="display: inline-block; width: 50%"
        >
          <el-input v-model="formLabelAlign.code"></el-input>
        </el-form-item>
        <el-form-item label="*值名称" style="display: inline-block; width: 50%">
          <el-input v-model="formLabelAlign.valueName"></el-input>
        </el-form-item>
        <el-form-item label="*值" style="display: inline-block; width: 50%">
          <el-input v-model="formLabelAlign.value"></el-input>
        </el-form-item>
        <el-form-item label="*版本号" style="display: inline-block; width: 50%">
          <el-input v-model="formLabelAlign.version"></el-input>
        </el-form-item>
        <el-form-item label="*状态" style="display: inline-block; width: 50%">
          <el-select
            v-model="formLabelAlign.status"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option label="正常" :value="0"> </el-option>
            <el-option label="弃用" :value="1"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="*分类编码"
          style="display: inline-block; width: 50%"
        >
          <el-input v-model="formLabelAlign.category"></el-input>
        </el-form-item>
        <el-form-item
          label="*分类名称"
          style="display: inline-block; width: 50%"
        >
          <el-input v-model="formLabelAlign.categoryName"></el-input>
        </el-form-item>

        <el-form-item
          label="是否必填"
          style="display: inline-block; width: 50%"
        >
          <el-switch
            v-model="formLabelAlign.isRequire"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-form-item>
        <el-form-item
          label="*标准等级"
          style="display: inline-block; width: 50%"
        >
          <el-input v-model="formLabelAlign.levelName"></el-input>
        </el-form-item>
        <el-form-item
          label="说明描述"
          style="display: inline-block; width: 100%"
        >
          <el-input v-model="formLabelAlign.descrption"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="btnOK" v-loading="allLoading"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      query: {
        currentPage: 1,
        pageSize: 16,
        filter: {
          type: 0,
        },
      },
      total: 0,
      tableData: [],
      title: "添加",
      dialogVisible: false,
      formLabelAlign: {
        isRequire: true,
        type: 0,
      },
      isLoading: false,
      allLoading: false,
    };
  },
  mounted() {
    this.getTabList();
  },
  methods: {
    getTabList(flag) {
      if (flag) {
        this.query.currentPage = 1;
      }
      this.isLoading = true;
      this.$post(
        baseUrl.jbIp + "/T1/api/v1/Platform/DyRange/GetList",
        this.query
      ).then((res) => {
        this.tableData = res.data.list;
        this.total = res.data.total;
        this.isLoading = false;
      });
    },
    handleClose() {
      this.dialogVisible = false;
      this.formLabelAlign = {
        isRequire: true,
        type: 0,
      };
      this.title = "添加";
      this.allLoading = false;
    },
    btnOK() {
      if (
        this.formLabelAlign.name == null ||
        this.formLabelAlign.code == null ||
        this.formLabelAlign.valueName == null ||
        this.formLabelAlign.value == null ||
        this.formLabelAlign.version == null ||
        this.formLabelAlign.status == null ||
        this.formLabelAlign.category == null ||
        this.formLabelAlign.categoryName == null ||
        this.formLabelAlign.levelName == null
      ) {
        this.$message({
          message: "请完整填写必填项！",
          type: "error",
        });
        return;
      }
      this.formLabelAlign.type = 0;
      if (!this.formLabelAlign.id) {
        this.allLoading = true;
        this.$post(
          baseUrl.jbIp + "/T1/api/v1/Platform/DyRange/Create",
          this.formLabelAlign
        ).then((res) => {
          if (res.code != 200) {
            this.$message.erroe(res.message);
            return;
          }
          this.getTabList();
          this.handleClose();
          this.$message({
            message: "操作成功",
            type: "success",
          });
        });
      } else {
        this.allLoading = true;
        this.$put(
          baseUrl.jbIp + "/T1/api/v1/Platform/DyRange/Update",
          this.formLabelAlign
        ).then((res) => {
          if (res.code != 200) {
            this.$message.error(res.message);
            return;
          }
          this.getTabList();
          this.handleClose();
          this.$message({
            message: "操作成功",
            type: "success",
          });
        });
      }
    },
    edit(val) {
      var init = JSON.stringify(val);
      this.formLabelAlign = JSON.parse(init);
      this.title = "修改";
      this.dialogVisible = true;
    },
    del(id) {
      this.$deleteF(
        baseUrl.jbIp + "/T1/api/v1/Platform/DyRange/Delete?id=" + id
      ).then((res) => {
        if (res.code != 200) {
          this.$message.error(res.message);
          return;
        }
        this.getTabList();
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
    },
    page_change(val) {
      this.query.currentPage = val;
      this.getTabList();
    },
  },
};
</script>

<style>
.SJZYLB {
  padding: 10px;
}
._body {
  height: 90vh;
}
</style>
